import logging.config
import os

from config import basedriver_config

# 日志目录创建
if not os.path.exists(basedriver_config.log_path):
    os.makedirs(basedriver_config.log_path)

# 日志配置
LOGGING_CONFIG = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "detailed": {
            "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        },
        "simple": {
            "format": "%(levelname)s | %(message)s"
        }
    },
    "handlers": {
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "simple",
            "level": "INFO"
        },
        "file": {
            "class": "logging.FileHandler",
            "formatter": "detailed",
            "level": "DEBUG",
            "filename": f"{basedriver_config.log_path}/app.txt",
            "encoding": "utf-8"
        },
        "errors": {
            "class": "logging.StreamHandler",
            "formatter": "detailed",
            "level": "ERROR",
            "stream": "ext://sys.stderr"
        }
    },
    "root": {
        "handlers": ["console", "file", "errors"],
        "level": "DEBUG",
        "encoding": "utf-8"
    }
}

logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger(__name__)
